$(function (){
    //加载默认隐藏展示页
    $(".show").hide()
    //单击后获取输入内容
    $(".btn").bind("click",function (){
        var text = $(".text").val();
        var title = $(".title").val();
        console.log(text)
        console.log(title)
        $.ajax({
            type: "post",
            url: "/nlp?action=artCate",
            data: {
                text: text,
                title: title
            },
            dataType: "json",
            success: function (data){
                console.log(data);
                //遍历data中的item
                var lv1 = data.item.lv1_tag_list.length;
                var lv2 = data.item.lv2_tag_list.length;
                console.log(data.item.lv1_tag_list);
                var htmlStr = "";
                htmlStr += "<p class=\"classes\">一级分类</p>"
                for(var i = 0;i < lv1;i++){
                    htmlStr += "<div class=\"bottom_div\"><p class=\"left_p\">一级分类标签:</p ><span class=\"right_span\">"+data.item.lv1_tag_list[i].tag+"</span></div>"
                    htmlStr += " <div class=\"bottom_div\"><p class=\"left_p\">一级权重:</p ><span class=\"right_span\">"+data.item.lv1_tag_list[i].score+"</span></div>"
                }
                htmlStr += "<p class=\"classes\">二级分类</p>"
                for(var i = 0;i < lv2;i++){
                    htmlStr += "<div class=\"bottom_div\"><p class=\"left_p\">二级标签:</p ><span class=\"right_span\">"+data.item.lv2_tag_list[i].tag+"</span></div>"
                    htmlStr += " <div class=\"bottom_div\"><p class=\"left_p\">二级权重:</p ><span class=\"right_span\">"+data.item.lv2_tag_list[i].score+"</span></div>"
                }
                //拼接到页面上
                $(".show").html(htmlStr);
                //给标题和文本框置空
                $(".title").val("");
                $(".text").val("");
            },
            err : function (data){
                console.log("失败")
            }
        })
        //单击后展示隐藏页面
        $(".show").show()
    })

})



